package top.xchch.tool.mockito.juejin;

import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

import java.util.List;

import static org.mockito.Mockito.mock;

/**
 * 为未stub的方法设置默认返回值
 *
 * @author sai.zhang
 * @date 2021-08-31 15:05
 */
public class DefaultValueTest13 {
    @Test
    public void testDefaultValue() throws Exception {

        List listOne = mock(List.class, Mockito.RETURNS_SMART_NULLS);
        List listTwo = mock(List.class, new Answer() {
            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable {
                // TODO: 2016/6/13 return default value here
                return "aa";
            }
        });

        Assert.assertEquals("aa", listTwo.get(1));
        Assert.assertEquals("aa", listOne.get(1));
    }

}
